<template>
    <div class="main-container"  :class="wrap?'main-wrap-container':'main-no-wrap-container'" id="search-mixin-id">
    <main-content :title="contentTitle" >
		<div slot="search">
		  <!-- 在此处放置搜索内容 -->
		  <div :class="[!searchFlag ? 'searchBox' : '']">
		    <el-form label-width="70px" style="display: inline-block; margin-right: 70px;">
		      <el-form-item label="姓名" style="display: inline-block;">
		        <el-input
		          v-model="searchParam.identify_name"
		          size="small"
		          placeholder="请输入姓名"
		          style="width:200px"
		        ></el-input>
		      </el-form-item>
		      <el-form-item label="房号" style="display: inline-block;">
		        <el-input
		          v-model="searchParam.room_number"
		          size="small"
		          placeholder="请输入房号"
		          style="width:200px"
		        ></el-input>
		      </el-form-item>
		      <el-form-item label="年份" label-width="50px" style="display: inline-block;">
		        <el-select
		          v-model="searchParam.year"
		          filterable
		          clearable
		          style="width:200px"
		          placeholder="请选择年份"
		        >
		          <el-option
		            v-for="(item,index) in year_Option"
		            :key="index"
		            :label="item"
		            :value="item"
		          ></el-option>
		        </el-select>
		      </el-form-item>
			  <el-form-item label="月份" label-width="50px" style="display: inline-block;">
			    <el-select
			      v-model="searchParam.month"
			      filterable
			      clearable
			      style="width:200px"
			      placeholder="请选择月份"
			    >
			      <el-option
			        v-for="(item,index) in month_Option"
			        :key="index"
			        :label="item.F_ItemName"
			        :value="item.F_ItemValue"
			      ></el-option>
			    </el-select>
			  </el-form-item>
		      <el-button
		        type="primary"
		        icon="el-icon-search"
		        size="small"
		        @click="searchClick"
		        style="margin:4px 0px 0px 5px"
		      >搜索</el-button>
		      <el-button
		        icon="el-icon-refresh"
		        size="small"
		        @click="searchReset"
		        style="margin-top:4px;"
		      >重置</el-button>
		      <!-- 展开/收起功能按钮 -->
		    </el-form>
		  </div>
		</div>
        <div slot="table">
        <!-- 在此处放置表格内容 -->
            <avue-crud ref="electricity_cost_records_monthTable" :data="listData" :showColumn="showColumn" :isSaveColumns="true"  id="printTable" :option="option" stripe :page.sync="page"
                       @on-load="onPageLoad"
                       @row-dblclick="handleRowDBLClick"
                       @sort-change="sortChange" 
                       @current-row-change="handleCurrentRowChange" >
                <template slot-scope="scope" slot="menu">
		  			   <template v-if="scope.row.flowStatus&&scope.row.flowStatus==2">
						  <span v-if="hasBtns('electricity_cost_records_month:createFormFlow') && hasButtonPermission('electricity_cost_records_month:createFormFlow')" class="form-span-button">{{$t("workFlow.WFChange.approval")}}</span>
						  <el-button type="opr-primary" size="mini"  icon="el-icon-view"  v-if="hasBtns('electricity_cost_records_month:view')&&hasButtonPermission('electricity_cost_records_month:view')" @click="viewForm(scope.row)">{{$t("crud.viewBtn")}}</el-button>
		  		 	   </template>
		  			   <template v-else-if="scope.row.flowStatus&&scope.row.flowStatus==3">
						  <span v-if="hasBtns('electricity_cost_records_month:createFormFlow') && hasButtonPermission('electricity_cost_records_month:createFormFlow')" class="form-span-button">{{$t("forme.editModal.approvalComplete")}}</span>
						  <el-button type="opr-primary" size="mini"  icon="el-icon-view"  v-if="hasBtns('electricity_cost_records_month:view')&&hasButtonPermission('electricity_cost_records_month:view')" @click.stop="viewForm(scope.row)">{{$t("crud.viewBtn")}}</el-button>
		  			   </template>
		  			   <template v-else>
			  			  <el-button type="opr-primary" size="mini" icon="el-icon-guide" v-if="scope.row.flowStatus&&scope.row.flowStatus==1&&hasBtns('electricity_cost_records_month:createFormFlow') && hasButtonPermission('electricity_cost_records_month:createFormFlow')" @click="CreateFormFlow(scope.row)">{{$t("forme.editModal.initiateApproval")}}</el-button>
			  			  <el-button type="opr-primary" size="mini" icon="el-icon-guide" v-if="hasBtns('electricity_cost_records_month:createDesignFlow') && hasButtonPermission('electricity_cost_records_month:createDesignFlow')" @click="CreateDesignFlow(scope.row)">{{$t("forme.editModal.createFormFlowBtn")}}</el-button>
			  			  <el-button type="opr-primary" size="mini"  icon="el-icon-view"  v-if="hasBtns('electricity_cost_records_month:view')&&hasButtonPermission('electricity_cost_records_month:view')" @click="viewForm(scope.row)">{{$t("crud.viewBtn")}}</el-button>
					   </template>
                </template>
                 <template slot="menuLeft">
                     <el-button type="primary"  v-if="hasButtonPermission('electricity_cost_records_month:add')" icon="el-icon-plus" size="small" @click="openForm()">{{$t("crud.addBtn")}}</el-button>
                     <el-button type="primary"  v-if="hasButtonPermission('electricity_cost_records_month:export')" icon="fa fa-sign-out" size="small" @click="tableExport()">{{$t("forme.editModal.quickExportBtn")}}</el-button>
                </template>
            </avue-crud>
            <el-dialog title="表单"  v-dialogDrag :append-to-body="true"  width="30%" height="30%"  :visible.sync="flag"  :class="isWorkflowForm ? 'work-form-dialog' : ''" :show-close="!isWorkflowForm" >
                <electricity_cost_records_monthForm ref="xtForm"  v-if="flag"  :isEdit="isEdit" :disabled="disabled" @onChange="dialogChange" ></electricity_cost_records_monthForm>
            </el-dialog>
			<el-dialog title="明细"  v-dialogDrag :append-to-body="true"  width="80%" height="30%"  :visible.sync="mxflag"  :class="isWorkflowForm ? 'work-form-dialog' : ''" :show-close="!isWorkflowForm" >
			    <electricity_cost_records_dayList ref="mxForm"  v-if="mxflag" @onChange="dialogChange" :year="year" :month="month" :identifyId="identifyId" :roomNumber="roomNumber"></electricity_cost_records_dayList>
			</el-dialog>
        </div>
    </main-content>
    <createFlow v-if="isCreateFlow" formType="2" rowPrimaryKey="fid" :UrlAddress="this.$options.name" :createFlowType="createFlowType" :row="scopeRow" :scheme="scheme" @closedCreateFlow="closedCreateFlow"></createFlow>
    </div>
</template>
<script>
      import createFlow from '@/components/formInitiationProcess/createFlow';
      import schemeMixins from '@/components/formInitiationProcess/schemeMixins';
     import MainFixed from "@/page/main/MainFixed";
      import authorizeMixin from "@/mixins/authorize";
      import tableOptionMixin from "@/mixins/tableOption"; //table 高度计算
      import tableSearchMixin from "@/mixins/tableSearch"; //table 搜索 
      import displayColumnsMixin from "@/mixins/displayColumns"; //表格展示列显隐保存 
     import MainContent from "@/page/main/MainContent";
      import request from '@/router/axios';
      import { baseUrl } from '@/config/env';
      import { getOrder } from '@/util/util';
      import electricity_cost_records_monthForm from './electricity_cost_records_monthForm';
	  import electricity_cost_records_dayList from './electricity_cost_records_dayList';
     export default {
         name: "electricity_cost_records_month",
         mixins: [authorizeMixin,tableOptionMixin,tableSearchMixin,displayColumnsMixin,schemeMixins],
         components: { MainContent, electricity_cost_records_monthForm,electricity_cost_records_dayList,createFlow,MainFixed },
         data() {
              return {
				 	  btns:[
				 	     'electricity_cost_records_month:refresh',
				 	     'electricity_cost_records_month:add',
				 	     'electricity_cost_records_month:view',
				 	     'electricity_cost_records_month:export'
                   ],
                   page: {
                       pageSize: 20,
                       total: 0,
                       currentPage: 1,
                       layout: "total, prev, pager, next, jumper"
                   },
                   listData: [],
                   flag:false,
				   mxflag:false,
                   isEdit: true, // 查看-不显示按钮,
                   disabled: false, // 查看-禁用input,
                   isWorkflowForm:false,//默认值 false
                   defaultOrderfield:'',//默认排序字段
                   defaultOrder:'',//默认排序
				   year:'',//年份
				   month:'',//月份
				   identifyId:'',//身份证号
				   roomNumber:'',//房间号
                   searchParam: {
					   identify_name:"",
					   room_number:"",
					   year:"",
					   month:"",
				   },
				   searchFlag: false, 
                   defaultProps: {
                       children: 'children',
                       label: ''
                   },
				   yearlist:[],
				   monthlist:[],
				   year_Option:[],
				   month_Option:[],
                   option:{
                       rowKey:'fid',
                       highlightCurrentRow: true,
                       stripe: true,
                       addBtn: false,
                       tip:false,
                       menuWidth: 80,
                       border: true,
                       page: true,
                       index: true,
                       menu: false,
                       indexLabel: this.$t('custmerForm.tableNumber'),
                       align: 'center',
                       menuAlign: 'left',
                       delBtn: false,
                       editBtn: false,
                       column: [
                           {
                               sortable: true,
                               label: this.$t("姓名"),
                               prop: 'identify_name',
                               overHidden: true,
                           },
						   {
						       sortable: true,
						       label: this.$t("性别"),
						       prop: 'gender',
						       overHidden: true,
						   },
                           {
                               sortable: true,
                               label: this.$t("身份证"),
                               prop: 'identify_id',
                               overHidden: true,
                           },
                           // {
                           //     sortable: true,
                           //     label: this.$t("事业部"),
                           //     prop: 'division',
                           //     overHidden: true,
                           // },
                           {
                               sortable: true,
                               label: this.$t("部门"),
                               prop: 'department',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("房号"),
                               prop: 'room_number',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("年份"),
                               prop: 'year',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("月份"),
                               prop: 'month',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("月度起始度数"),
                               prop: 'mineng',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("月度截止度数"),
                               prop: 'maxeng',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("用电量"),
                               prop: 'eng_reality',
                               overHidden: true,
                           },
						   {
						       sortable: true,
						       label: this.$t("电表月度起始度数"),
						       prop: 'mineng',
						       overHidden: true,
						   },
						   {
						       sortable: true,
						       label: this.$t("电表月度截止度数"),
						       prop: 'maxeng',
						       overHidden: true,
						   },
                           {
                               sortable: true,
                               label: this.$t("电费单价"),
                               prop: 'electricity_price',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("电费"),
                               prop: 'cost',
                               overHidden: true,
                           },
                       ]
                   }
              }
                   },
                   created() {
					   
                       //是否有编辑 查看 删除 发起流程 发起临时流程权限 无则为操作列不显示
                       let oprBtns = ['electricity_cost_records_month:modify','electricity_cost_records_month:view','electricity_cost_records_month:delete','electricity_cost_records_month:createFormFlow','electricity_cost_records_month:createDesignFlow'];
                       let intersection = this.btns.filter((v) => oprBtns.includes(v)); 
                       if(intersection.length>0){
                       	this.option.menu =  true
                       }else{
                       	this.option.menu = false
                       }
      //                  let querySearchData = [
      //                  	{ 
      //                  		name: '姓名', 
      //                  		DateField: '', 
      //                  		field: 'identify_name', 
      //                  		tag: 'el-input', 
      //                  		avueType: 'input-tip', 
      //                  		lgmark: '', 
      //                  	}, 
      //                  	{ 
      //                  		name: '房号', 
      //                  		DateField: '', 
      //                  		field: 'room_number', 
      //                  		tag: 'el-input', 
      //                  		avueType: 'input-tip', 
      //                  		lgmark: '', 
      //                  	}, 
      //                   {
      //                   	name: '年份', 
      //                   	DateField: '', 
      //                   	field: 'year', 
      //                   	tag: 'el-radio-group', 
      //                   	avueType: 'radio', 
      //                   	lgmark: '', 
      //                   	dataType: 'dataItem', 
      //                   	dataItem: 'date_year', 
      //                   },  
						// {
						// 	name: '月份', 
						// 	DateField: '', 
						// 	field: 'month', 
						// 	tag: 'el-radio-group', 
						// 	avueType: 'radio', 
						// 	lgmark: '', 
						// 	dataType: 'dataItem', 
						// 	dataItem: 'date_month', 
						// }, 
      //                  ]
					   this.getsearch_Option();
					   this.getmonth_Option();
                       // this.getSystemSearchList(querySearchData);
                       if(this.btns.length>0){
                       	let tempBtns =  this.btns.concat(oprBtns).filter((v) => this.btns.includes(v) && !oprBtns.includes(v));
                       	if(tempBtns.length>0){
                       		this.searchBtns  = [...new Set([...tempBtns])];
                       	}
                       }
                   },
                   methods: {
                         handleRowDBLClick (row, event) {
                         	if(this.hasBtns('electricity_cost_records_month:modify')&&this.hasButtonPermission('electricity_cost_records_month:modify')&&this.openDoubleClickEdit){
                         		this.editForm(row)
                         	}
                         },
                         handleCurrentRowChange(row){
                         	this.$refs.electricity_cost_records_monthTable.toggleSelection([row]);
                         },
                         printForm() {
                         	let element = window.document.getElementById("printTable");
                         	setTimeout(() => {
                         	  html2canvas(element, {
                         		backgroundColor: null,
                         		useCORS: true,
                         		windowHeight: document.body.scrollHeight
                         	  }).then(canvas => {
                         		const url = canvas.toDataURL();
                         		this.printImg = url;
                         		printJS({
                         		  printable: url,
                         		  type: "image",
                         		  documentTitle: '打印',
                         		  scanStyles: false,
                         		  repeatTableHeader: false,
                         		  header: null
                         		});
                          	  });
                         	}, 1);
                           },
                         hasBtns(encode){
                         	return this.btns.includes(encode);
                         },
                         /**发起流程 */
                         CreateDesignFlow(val) {
                            this.createFlowType = 0;
                            this.scopeRow = val;
                            this.changeSystemSchemeInfo();
                         },
                         CreateFormFlow(val) {
                            this.createFlowType = 1;
                            this.scopeRow = val;
                            this.isCreateFlow = true;
                         },
                         /* 获取公司用户数据 */
                         getListData() {
                         	if(!this.searchParam.order){
                         		this.searchParam.orderfield = this.defaultOrderfield;
                         		this.searchParam.order = this.defaultOrder;
                         	}
                            let params = this.changeSearchParams();
                            request({
                                url: baseUrl + '/electricity_cost_records_month',
                                method: 'get',
                                params: params
                            }).then(res =>{
                                this.listData = res.data.data.Rows
                                this.page.total = res.data.data.Total;
                            })
                         },
						 getsearch_Option() {
							 const now = new Date();
							 const year = now.getFullYear();
							 console.log(year);
							 this.yearlist = [year-1,year,year+1];
							 console.log(this.yearlist)
							 this.year_Option= this.yearlist;
        //                     request({
								
        //                         url: baseUrl + '/electricity_cost_records_month',
        //                         method: 'get',
                                
        //                     }).then(res =>{
								// this.yearlist=[];
								// this.monthlist=[];
								// res.data.data.Rows.forEach((item)=>{
								// 	this.yearlist.push(item.year)
									
								// })
								// // console.log(this.yearlist)
        //                         this.year_Option = [...new Set(this.yearlist)];
								
								
        //                     })
                         },
						 async getmonth_Option() {
						   // 注意：this.$axios是通过Vue.prototype.$axios = axios挂载产生的
						   try {
						     let resp = await this.$axios({
						       method: 'get',
						       url:  baseUrl + '/data-items/date_month/detail',
						     });
						     if (resp.data.data) {
						       this.month_Option = resp.data.data;
						     }
						   }
						   catch (error) {}
						 },
                         /* 页面加载 */
                         onPageLoad(page) {
                            this.searchParam.limit = page.currentPage;
                            this.searchParam.size = page.pageSize;
                            this.getListData();
                         },
                          /*查看*/
                         viewForm(val) {
                           this.mxflag = true;
						   this.year = val.year; 
						   this.month = val.month; 
						   this.identifyId = val.identify_id; 
						   this.roomNumber = val.room_number;
                         },
                          /* 打开表单 */
                         openForm(){
							  if(!this.isWorkflowForm){
                             //不处理工作流表单时候，表单类型重置
                             window.localStorage.setItem('systemFormType',0);
                           }
                           this.disabled = false;
                           this.flag = true; 
                           this.isEdit = true; 
                         },
                          /* 分页 */
                         sortChange(data) {
                         	if(data.order){
                         		let order= getOrder(data.order);
                         		this.searchParam.order = order;
                         		this.searchParam.orderfield = data.prop;
                         	}else{
                         		this.searchParam.order = this.defaultOrder;
                         		this.searchParam.orderfield = this.defaultOrderfield;
                         	}
                         	this.getListData()
                         },
                          /* 弹窗回调 */
                          dialogChange(b){
                              this.flag = false;
							  this.mxflag = false;
                              this.$nextTick(()=>{
                              this.getListData();
                         })},
                          /* 导出 */
                          tableExport(){
                            this.$refs["electricity_cost_records_monthTable"].rowExcel()
                            return;
                         },
                          /* 查询 */
                           searchClick(params) {
                           this.searchParam.limit = 1;
                           this.searchParam.order = null;
                           this.searchParam.orderfield = null;
                           this.getListData();
							
                         },
                           /* 查询表单重置 */
                           searchReset() {
                            this.searchParam.identify_name = null;
                            this.searchParam.room_number = null;
                            this.searchParam.year = null; 
							this.searchParam.month = null;					  
                            this.getListData();
							this.getsearch_Option();
                         }, 
         }
     }
</script>
<style scoped>
.searchBox {
   width: calc(100% - 218px);
   display: inline-block;
}
.main-container{
   height: 100%!important;
   padding: 0 8px!important;
}
div /deep/ .custom-tree-node span{
   font-size: 14px;
   padding-left: 10px;
}
div /deep/ .custom-tree-node i{
   font-size: 12px;
}
div /deep/ .el-dialog__body{
height: 70vh;
overflow: scroll;
}
</style>
